package com.fgs.common.imageView.strategy;

import android.widget.ImageView;

import com.fgs.common.imageView.strategy.impl.GlideImageLoaderStrategy;


/**
 * @author fgs
 * @date 2020/5/12
 * @description
 **/
public class ImageLoader implements IImageLoaderStrategy {
    private static volatile ImageLoader INSTANCE = null;

    private IImageLoaderStrategy iImageLoaderStrategy;

    private ImageLoader() {
        iImageLoaderStrategy = new GlideImageLoaderStrategy();
    }

    public ImageLoader setImageLoaderStrategy(IImageLoaderStrategy iImageLoaderStrategy) {
        this.iImageLoaderStrategy = iImageLoaderStrategy;
        return this;
    }

    public IImageLoaderStrategy getImageLoaderStrategy() {
        return iImageLoaderStrategy;
    }

    public static ImageLoader init() {
        if (INSTANCE == null) {
            synchronized (ImageLoader.class) {
                if (INSTANCE == null) {
                    INSTANCE = new ImageLoader();
                }
            }
        }
        return INSTANCE;
    }


    @Override
    public void loadImageWithId(ImageView imageView, String imageId) {
        iImageLoaderStrategy.loadImageWithId(imageView, imageId);
    }

    @Override
    public void loadImageWithIdAndSuffix(ImageView imageView, String imageId) {
        iImageLoaderStrategy.loadImageWithIdAndSuffix(imageView, imageId);
    }

    @Override
    public void loadImageWithId(ImageView imageView, String imageId, boolean isNeedCache) {
        iImageLoaderStrategy.loadImageWithId(imageView, imageId, isNeedCache);
    }

    @Override
    public void loadImageWithUrl(ImageView imageView, String url, boolean isNeedCache) {
        iImageLoaderStrategy.loadImageWithUrl(imageView, url, isNeedCache);
    }

    @Override
    public void loadImageWithUrl(ImageView imageView, String url, int defaultImage) {
        iImageLoaderStrategy.loadImageWithUrl(imageView, url, defaultImage);
    }
}
